using UnityEngine;

public class FollowObjectOnScreen : MonoBehaviour
{
	public Transform transformToFollow;

	public float alpha = 1f;

	private UIWidget widget;

	private void Awake()
	{
		widget = GetComponent<UIWidget>();
	}

	private void Update()
	{
		if (!(transformToFollow == null))
		{
			if (!widget.gameObject.activeSelf)
			{
				widget.alpha = 0f;
			}
			else
			{
				widget.alpha = alpha;
			}
			Vector3 position = UICamera.mainCamera.ScreenToWorldPoint(Camera.main.WorldToScreenPoint(transformToFollow.position));
			position.z = widget.cachedTransform.position.z;
			widget.cachedTransform.position = position;
		}
	}
}
